package com.chenfan.filestore.mq.task;

import com.chenfan.filestore.config.DS;
import com.chenfan.filestore.config.DynamicDataSourceRegister;
import com.chenfan.print.vo.BaseDatabaseVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.chenfan.filestore.common.Constants.REFRESH_DB_TASK_TOPIC;

@Service
@Slf4j
@RocketMQMessageListener(topic = REFRESH_DB_TASK_TOPIC, messageModel = MessageModel.BROADCASTING, consumerGroup = REFRESH_DB_TASK_TOPIC)
public class RefreshDBConsumer extends BaseMqConsumer implements RocketMQListener<List<BaseDatabaseVO>> {

    @Autowired
    private DynamicDataSourceRegister dynamicDataSourceRegister;

    @Override
    @DS
    public void onMessage(List<BaseDatabaseVO> dbs) {
        dynamicDataSourceRegister.refreshDB();
    }

}
